package com.scs.application.modules.adm.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.scs.application.core.exception.BusinessException;
import com.scs.application.core.service.BaseServiceImpl;
import com.scs.application.modules.adm.entity.MatrInquiryTarget;
import com.scs.application.modules.adm.mapper.MatrInquiryTargetMapper;
import com.scs.application.modules.adm.service.MatrInquiryTargetService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 耗材准入询价目标 服务实现类
 * </p>
 */
@Service
public class MatrInquiryTargetServiceImpl extends BaseServiceImpl<MatrInquiryTargetMapper, MatrInquiryTarget> implements MatrInquiryTargetService {
    @Override
    public boolean saveOrUpdate(MatrInquiryTarget entity) {
        Integer count = baseMapper.selectCount(Wrappers.<MatrInquiryTarget>query().eq("apply_item_id", entity.getApplyItemId()).eq("supplier_name",entity.getSupplierName()));
        if (count > 0) {
            throw new BusinessException("该询价明细已添加过供应商【%s】，不可以重复添加",entity.getSupplierName());
        }
        return super.saveOrUpdate(entity);
    }
}
